<style lang="less">
@import '../../../assets/style/renyuanxuanze.less';
.gt_list .van-cell .van-cell__title {
	line-height: 20px!important;
	.aaa{
		font-size: 12px;
		color: #909192;
	}
}
.pop_up{
	.van-popup {
		width: 85%;
		padding: 10px;
		max-height: 80%;
		min-height: 18%;
		text-align: left;
		.list_box{
			font-size:14px;
			border-bottom:1px dotted #ddd;
			.title {
				display: inline-block;
				width: 30%;
			}
		}
	}
}
</style>

<template>
	<mxq-router-layout>
		<div class=" towerList">
			<Head slot="header" @headerClick="headerClick($event)">
				<div slot="headerTitle">
					值守杆塔
				</div>
				<div slot="headerRight">
					<i class="iconfont icon-shouye"/>
					<!-- <van-icon class="home" name="home"/> -->
				</div>
				<!-- <div slot="headerRight">
					导航
				</div> -->
			</Head>

			<ganta-List
				:gantaList="gtLists"
				:picUrlLeft="picUrlLeft"
				:listTitle="listTitle"
				@clickList="clickList">
			</ganta-List>

			<!-- 隐 -->
			<div class="pop_up">
				<van-popup v-model="yin">
					<div>
						<div v-for="(item,index) in hiddenData" :key="index" class="list_box">
							<p>
								<span class="title">分类：</span>
								<span class="name">{{item.NAME}} ({{item.TYPE ? '隐' : "1"}})</span>
							</p>
							<p>
								<span class="title">发现时间：</span>
								<span class="name">{{item.TIME}}</span>
							</p>
							
							<p>
								<span class="title">等级：</span>
								<span class="name">{{item.LEVEL_}}</span>
							</p>
							<p>
								<span class="title">状态：</span>
								<span class="name">{{item.STATUS}}</span>
							</p>
							<p>
								<span  class="title">责任人：</span>
								<span class="name">{{true?item.USERNAME:''}}</span>
							</p>
						</div>
					</div>
				</van-popup>
			</div>

			<!-- 缺陷 -->
			<div class="pop_up">
				<van-popup v-model="que">
					<div>
						<div v-for="(item,index) in defectsData" :key="index" class="list_box">
							<p>
								<span  class="title">分类：</span>
								<span class="name">{{item.NAME}} ({{item.TYPE ? '缺' : "0"}})</span>
							</p>
							<p>
								<span  class="title">发现时间：</span>
								<span class="name">{{item.TIME}}</span>
							</p>
							
							<p>
								<span class="title">等级：</span>
								<span class="name">{{item.LEVEL_}}</span>
							</p>
							<p>
								<span class="title">状态：</span>
								<span class="name">{{item.STATUS}}</span>
							</p>
							<p>
								<span class="title">责任人：</span>
								<span class="name">{{true?item.USERNAME:''}}</span>
							</p>
						</div>
					</div>
				</van-popup>
			</div>

			<div class="pop_up">
				<van-popup v-model="yinAndQue">
					<div class="con_box">
						<div v-for="(item,index) in hiddenDefectsData" :key="index" class="list_box">
							<p>
								<span class="title">分类：</span>
								<span class="name" v-if="item.TYPE=='0'">{{item.NAME}} ({{item.TYPE ? '缺' : "0"}})</span>
								<span class="name" v-else>{{item.NAME}} ({{item.TYPE ? '隐' : "1"}})</span>
							</p>
							<p>
								<span class="title">发现时间：</span>
								<span class="name">{{item.TIME}}</span>
							</p>
							<p>
								<span class="title">等级：</span>
								<span class="name">{{item.LEVEL_}}</span>
							</p>
							<p>
								<span class="title">状态：</span>
								<span class="name">{{item.STATUS}}</span>
							</p>
							<p>
								<span class="title">责任人：</span>
								<span class="name">{{true?item.USERNAME:''}}</span>
							</p>
						</div>
					</div>
				</van-popup>
			</div>
		</div>
	</mxq-router-layout>
</template>

<script>
import Head from '../../../components/head'
import GantaList from '../../../components/ganta-list'
import IconGT from '../../../assets/img/changguixunshi/icon_gt.png'
import { callData } from '../../../axios/axios'

import {
	Icon,
	Toast,
	Popup
} from 'vant'

export default {
	name:'gantaxunshi',
    components: {
		Head,
		// XsList,
		GantaList,
		[Icon.name]: Icon,
		[Popup.name]: Popup
	},
	data() {
		return {
			value:'',
			gtLists:[],
			picUrlLeft: IconGT,			//列表左侧图片
			listTitle: ['','已巡视次数：',''],
			yin:false,					//隐
			hiddenData: [],				//隐患数据
			listType: [],				//隐患详情Key
			detailShow: [],				//数据集合
			que:false,					//缺
			defectsData: [],			//缺陷数据
			hiddenDefectsData:[],	//隐患和缺陷数据
			yinAndQue: false,			//隐和缺
		}
	},
	mounted() {
		this.getListData();
    },
    methods: {
		// 头部两侧按钮点击事件
		headerClick(e){
			// alert('安卓地图导航');
			this.$router.push({name:"index"})
		},
		// 任务列表点击事件 跳页
		clickList(e){
			console.log(e)
			let query = {
				zsTaskId: this.$route.query.zsTaskId,
				xsTowerTaskId: e.data.ID,
				towerId:e.data.TOWER_ID,
				towerTaskId:e.data.TOWERTASKID,
				lineId:e.data.LINE_ID,
				lineName:e.data.LINE_NAME,
				towerName:e.data.TOWER_NAME,
				taskId :e.data.ZS_BD_TASK_ID,
				lineTowerId :e.data.LINE_TOWER_ID,
				status: e.data.TASKSTATUS,//任务状态
				towerStatus: e.data.STATUS,//杆塔的状态
				page: this.$route.query.page,
				size: this.$route.query.size,
				index: this.$route.query.index
			}
			if(e.todo == -1){
				var _this = this;
				var params = {};
				params.towerId = e.data.TOWER_ID;
				if(e.data.IS_YH=="1" && e.data.IS_QX=="0"){ //隐
					callData('/accountServer/YhDefectCheck/findyhDefectTaskTowerList', 'get', params).then(res => {
						if(res.success){
							_this.yin = true;
							var resHidden = res.data;
							_this.hiddenData = resHidden;
						}
					})
				}
				else if(e.data.IS_QX=="1" && e.data.IS_YH=="0"){//缺
					callData('/accountServer/YhDefectCheck/findyhDefectTaskTowerList', 'get', params).then(res => {
						if(res.success){
							_this.que = true;
							var resDefects = res.data;
							_this.defectsData = resDefects;
						}
					})
				}
				else if(e.data.IS_YH=="1" && e.data.IS_QX=="1"){//隐和缺
					callData('/accountServer/YhDefectCheck/findyhDefectTaskTowerList', 'get', params).then(res => {
						if(res.success){
							_this.yinAndQue = true;
							var hiddendefects = res.data;
							_this.hiddenDefectsData = hiddendefects;
						}
					})
				}else {}
			}
			//一条任务中的杆塔只打一次卡
			else if(e.todo == 1 && e.data.TASKSTATUS == 0){//任务未开始，需要先打一次卡
				this.$router.push({
					name: 'bdzs_noPhotos',
					query
				})
			}
			else if(e.todo == 1 && e.data.TASKSTATUS == 1 && e.data.STATUS == 0){
				//已打过卡之后,需要判断：总任务已开始status=1，杆塔未开始towerStatus=0，则先调一次杆塔任务开始的接口
	        	callData('/zsTaskServer/ZsBdTowerTask/appZsTowerStart', 'put', {
	            	xsTowerTaskId:e.data.TOWERTASKID
	            }).then(res => {
	                if(res.success){
	                	Toast(res.data)
	                	this.$router.push({
	                  		path:'/bdzs_allowPhotos',
	                  		query
	             		})
	                }else{
						Toast(res.data);
	                }
	            })
	        }else if(e.todo == 1 && e.data.TASKSTATUS == 1 && e.data.STATUS == 1){
	        	this.$router.push({
              		path:'/bdzs_allowPhotos',
              		query
         		})
	        }else if(e.tode==1 && e.data.TASKSTATUS == 2 && e.data.STATUS == 2){
				query.name = 'bdzs_allowPhotos'
				query.towerStatus = 2
				this.$router.push({
					name: 'bdzs_allowPhotos',
					query: query
				})
			}
		},
		// 拿到杆塔的列表信息
		getListData() {
			var params = {};
			params.page = this.$route.query.page;
			params.size = this.$route.query.size;
			params.zsTaskId = this.$route.query.zsTaskId;
			callData('/zsTaskServer/ZsBdTowerTask/appZsTowerTasks', 'get', params).then(res => {
				var gtData = res.data.content;
				gtData.forEach((item,index) => {
					item.textName = item.LINE_NAME_SHORT + ' - ' + item.TOWER_NAME + '杆塔'; //杆塔名称
					item.gtnum = item.XS_NUMBER; //巡视次数
					item.cname = "btn_statusNo";
					item.cname1 = "btn_statusNo";
					item.alarm=item.IS_YH==1?'have':'';
					item.que=item.IS_QX==1?'have':'';
					// item.status = item.STATUS; //杆塔是否开始的状态
					// item.cname="btn_statusNo";
					// 杆塔状态判断
					if (item.STATUS == 1){
						item.status = item.STATUS
						item.statusName = '进行中'
						item.cname="btn_status1"
					}
				})
				this.gtLists = gtData;
			})
		}
	}
}
</script>
